package com.tanhua.server.controller;

/**
 * @Author: cl
 * @Date: 2022/5/11 - 05 - 11
 * @Description:
 */

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 小视频模块
 */
@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private SmallVideosService smallVideosService;

    /**
     * 发布小视频
     *
     * @param videoThumbnail 封面图片
     * @param videoFile      小视频
     * @return
     */
    @PostMapping()
    public ResponseEntity send(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {

        smallVideosService.send(videoThumbnail, videoFile);
        return ResponseEntity.ok("发布成功！");
    }

    /**
     * 查询小视频
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping()
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) {

        PageResult pr = smallVideosService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(pr);
    }
}
